package com.xmutca.sso.sdk.realm;

import com.xmutca.sso.api.server.AccountService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-08 21:38
 */
public class ClientRealm extends AuthorizingRealm {

    private final static Logger logger = LoggerFactory.getLogger(ClientRealm.class);

    private AccountService accountService;

    /**
     * 授权，
     * @param principalCollection
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        System.out.println("doGetAuthorizationInfo");
        return new SimpleAuthorizationInfo();
    }

    /**
     * 认证, sso校验以后app不再校验
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        System.out.println("doGetAuthenticationInfo");
        return new SimpleAuthenticationInfo();
    }

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
}
